package cn.cloudreal.cbms.statements.dao.impl;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.cloudreal.cbms.common.util.PageBean;
import cn.cloudreal.cbms.statements.dao.ResourceStateDao;
import cn.cloudreal.cbms.vo.ResourceState;

public class ResourceStateDaoImpl extends SqlMapClientDaoSupport implements ResourceStateDao{
	
	private final String GET_LIST = "resourceState.getResourceStateList";
	private final String GET_COUNT = "resourceState.getResourceStateCount";
	/** 日志工具类实例 */
    private static final Logger log = Logger.getLogger(ProjectPriceDaoImpl.class);

	/**
	 * 资源状态累计金额统计表
	 */
	public List<ResourceState> getResourceStateList(Map condition,
			PageBean page) {
		// 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter AccrualDaoImpl getResourceStateList() method, return List<ResourceState>");
        }
        
		List<ResourceState> resourceStateList = null;
        //分页功能
        int totalCount = getResourceStateCount(condition);
        System.out.println("totalCount===="+totalCount);
        page.setTotalRecords(totalCount);
		// 总记录数不为零才查询
        if (totalCount != 0)
        {
        	condition.put("i_type", 2);
    		condition.put("i_startid", (page.getPageNo()-1) * page.getPageSize()+1);
    		condition.put("i_endid", (page.getPageNo()-1) * page.getPageSize() + page.getPageSize());
        	// 查询
    		resourceStateList = getSqlMapClientTemplate().queryForList(GET_LIST, condition);
        }
        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit AccrualDaoImpl getResourceStateList() method, return List<ResourceState>");
        }
        return resourceStateList;
	}
	

	/**
	 * 资源状态累计金额统计数目
	 */
	public int getResourceStateCount(Map condition) {
		Object count = 0;
		try 
		{
			condition.put("i_type", 1);
			count = this.getSqlMapClientTemplate().queryForObject(GET_COUNT, condition);
			System.out.println("count========>"+count);
		} catch (Exception e) {
		      e.printStackTrace();
		}
		return count == null ? 0 : (Integer)count;
	}
	

}
